﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Activity.Infrastructure.Migrations
{
    /// <inheritdoc />
    public partial class Initial : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            // migrationBuilder.CreateSequence(
            //     name: "EntityFrameworkHiLoSequence",
            //     incrementBy: 10);

            migrationBuilder.CreateTable(
                name: "T_VoluntaryActivity",
                columns: table => new
                {
                    ActivityId = table.Column<long>(type: "bigint", nullable: false),
                    ActivityName = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    ActivityTypes = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    ActivityComplete = table.Column<bool>(type: "bit", nullable: false),
                    ActivityCompleteTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    ActivityDescription = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    OrganizerId = table.Column<long>(type: "bigint", nullable: false),
                    ActivityDetailAddress = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false),
                    CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_T_VoluntaryActivity", x => x.ActivityId)
                        .Annotation("SqlServer:Clustered", true);
                });

            migrationBuilder.CreateTable(
                name: "MapPoints",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false),
                    Latitude = table.Column<double>(type: "float", nullable: false),
                    Longitude = table.Column<double>(type: "float", nullable: false),
                    ActivityId = table.Column<long>(type: "bigint", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MapPoints", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MapPoints_T_VoluntaryActivity_ActivityId",
                        column: x => x.ActivityId,
                        principalTable: "T_VoluntaryActivity",
                        principalColumn: "ActivityId",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "T_ActivityReviews",
                columns: table => new
                {
                    ReviewId = table.Column<long>(type: "bigint", nullable: false),
                    ActivityId = table.Column<long>(type: "bigint", nullable: false),
                    ReviewContent = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    CreateTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_T_ActivityReviews", x => x.ReviewId)
                        .Annotation("SqlServer:Clustered", true);
                    table.ForeignKey(
                        name: "FK_T_ActivityReviews_T_VoluntaryActivity_ActivityId",
                        column: x => x.ActivityId,
                        principalTable: "T_VoluntaryActivity",
                        principalColumn: "ActivityId",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "T_ActivityVolunteer",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false),
                    ActivityId = table.Column<long>(type: "bigint", nullable: false),
                    VolunteerId = table.Column<long>(type: "bigint", nullable: false),
                    JoinTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    DepartTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    IsDeparted = table.Column<bool>(type: "bit", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_T_ActivityVolunteer", x => x.Id);
                    table.ForeignKey(
                        name: "FK_T_ActivityVolunteer_T_VoluntaryActivity_ActivityId",
                        column: x => x.ActivityId,
                        principalTable: "T_VoluntaryActivity",
                        principalColumn: "ActivityId",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_MapPoints_ActivityId",
                table: "MapPoints",
                column: "ActivityId");

            migrationBuilder.CreateIndex(
                name: "IX_T_ActivityReviews_ActivityId",
                table: "T_ActivityReviews",
                column: "ActivityId");

            migrationBuilder.CreateIndex(
                name: "IX_T_ActivityVolunteer_ActivityId",
                table: "T_ActivityVolunteer",
                column: "ActivityId");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "MapPoints");

            migrationBuilder.DropTable(
                name: "T_ActivityReviews");

            migrationBuilder.DropTable(
                name: "T_ActivityVolunteer");

            migrationBuilder.DropTable(
                name: "T_VoluntaryActivity");

            // migrationBuilder.DropSequence(
            //     name: "EntityFrameworkHiLoSequence");
        }
    }
}
